#!/bin/sh

# This hook checks for branches named .../project-XXX-description
# and automatically prepends [PROJECT-XXX] to the commit messages

[[ -n "$(cat $1 | grep 'fixup!')" ]] && FIXUP="YES"

TICKET=$(git symbolic-ref HEAD | rev | cut -d/ -f1 | rev | tr a-z A-Z | grep -o -E "[A-Z]+-[0-9]+" | head -n1)
if [[ -n "${TICKET}" && -z "${FIXUP}" ]]; then
    sed -i.bak -e "1s/^/[${TICKET}] /" $1
fi
